DEFINITION FOR AMIGALIB MODULE Serial ;

FROM SYSTEM IMPORT SHORTSET ;
FROM Exec   IMPORT CMD_NONSTD, IOStdReq ;

TYPE
(* array of termination char's	   *)
(* to use,see serial.doc setparams *)

  IOTArrayPtr = POINTER TO IOTArray ;
  IOTArray = RECORD
    TermArray0 : LONGINT ;
    TermArray1 : LONGINT ;
  END ;

CONST
  SER_DEFAULT_CTLCHAR = 11130000H ; (* default chars for xON,xOFF *)

(* You may change these via SETPARAMS.	At this time, parity is not	*)
(* calculated for xON/xOFF characters.	You must supply them with the	*)
(* desired parity.							*)

(************************************************************************)
(*									*)
(* CAUTION !!  IF YOU ACCESS the serial.device, you MUST (!!!!) use an  *)
(* IOExtSer-sized structure or you may overlay innocent memory !!	*)
(*									*)
(************************************************************************)

TYPE
  IOExtSerPtr = POINTER TO IOExtSer ;
  IOExtSer = RECORD
    IOSer	 : IOStdReq  ;
    io_CtlChar	 : LONGINT   ; (* control char's (order = xON,xOFF,INQ,ACK)   *)
    io_RBufLen	 : LONGINT   ; (* length in bytes of serial port's read buffer*)
    io_ExtFlags	 : LONGINT   ; (* additional serial flags (see bitdefs below) *)
    io_Baud	 : LONGINT   ; (* baud rate requested (true baud)	      *)
    io_BrkTime	 : LONGINT   ; (* duration of break signal in MICROseconds    *)
    io_TermArray : IOTArray  ; (* termination character array		      *)
    io_ReadLen	 : SHORTCARD ; (* bits per read character (# of bits)	      *)
    io_WriteLen	 : SHORTCARD ; (* bits per write character (# of bits)	      *)
    io_StopBits	 : SHORTCARD ; (* stopbits for read (# of bits)		      *)
    io_SerFlags	 : SHORTSET  ; (* see SerFlags bit definitions below	      *)
    io_Status	 : CARDINAL  ;
  END ;

(* status of serial port, as follows:					      *)
(*		   BIT	ACTIVE	FUNCTION				      *)
(*		    0	 ---	reserved				      *)
(*		    1	 ---	reserved				      *)
(*		    2	 high	Connected to parallel "select" on the A1000.  *)
(*				Connected to both the parallel "select" and   *)
(*				serial "ring indicator" pins on the A500 &    *)
(*				A2000.	Take care when making cables.	      *)
(*		    3	 low	Data Set Ready				      *)
(*		    4	 low	Clear To Send				      *)
(*		    5	 low	Carrier Detect				      *)
(*		    6	 low	Ready To Send				      *)
(*		    7	 low	Data Terminal Ready			      *)
(*		    8	 high	read overrun				      *)
(*		    9	 high	break sent				      *)
(*		   10	 high	break received				      *)
(*		   11	 high	transmit x-OFFed			      *)
(*		   12	 high	receive x-OFFed				      *)
(*		13-15		reserved				      *)

CONST
  SDCMD_QUERY		= CMD_NONSTD ;
  SDCMD_BREAK		= CMD_NONSTD + 1 ;
  SDCMD_SETPARAMS	= CMD_NONSTD + 2 ;

  SERB_XDISABLED	=  7  ;	(* io_SerFlags xOn-xOff feature disabled bit *)
  SERF_XDISABLED	= {7} ;	(*    "	    xOn-xOff feature disabled mask   *)
  SERB_EOFMODE		=  6  ;	(*    "	    EOF mode enabled bit	     *)
  SERF_EOFMODE		= {6} ;	(*    "	    EOF mode enabled mask	     *)
  SERB_SHARED		=  5  ;	(*    "	    non-exclusive access bit	     *)
  SERF_SHARED		= {5} ;	(*    "	    non-exclusive access mask	     *)
  SERB_RAD_BOOGIE	=  4  ;	(*    "	    high-speed mode active bit       *)
  SERF_RAD_BOOGIE	= {4} ;	(*    "	    high-speed mode active mask      *)
  SERB_QUEUEDBRK	=  3  ;	(*    "	    queue this Break ioRqst	     *)
  SERF_QUEUEDBRK	= {3} ;	(*    "	    queue this Break ioRqst	     *)
  SERB_7WIRE		=  2  ;	(*    "	    RS232 7-wire protocol	     *)
  SERF_7WIRE		= {2} ;	(*    "	    RS232 7-wire protocol	     *)
  SERB_PARTY_ODD	=  1  ;	(*    "	    parity feature enabled bit	     *)
  SERF_PARTY_ODD	= {1} ;	(*    "	    parity feature enabled mask	     *)
  SERB_PARTY_ON		=  0  ;	(*    "	    parity-enabled bit		     *)
  SERF_PARTY_ON		= {0} ;	(*    "	    parity-enabled mask		     *)

(* These now refect the actual bit positions in the io_Status UWORD *)

  IO_STATB_XOFFREAD	=  12 ;	(* io_Status receive currently xOFF'ed bit    *)
  IO_STATF_XOFFREAD	= {12}; (*	 "     receive currently xOFF'ed mask *)
  IO_STATB_XOFFWRITE	=  11 ;	(*	 "     transmit currently xOFF'ed bit *)
  IO_STATF_XOFFWRITE	= {11}; (*	 "     transmit currently xOFF'ed mask*)
  IO_STATB_READBREAK	=  10 ;	(*	 "     break was latest input bit     *)
  IO_STATF_READBREAK	= {10}; (*	 "     break was latest input mask    *)
  IO_STATB_WROTEBREAK	=  9  ;	(*	 "     break was latest output bit    *)
  IO_STATF_WROTEBREAK	= {9} ; (*	 "     break was latest output mask   *)
  IO_STATB_OVERRUN	=  8  ;	(*	 "     status word RBF overrun bit    *)
  IO_STATF_OVERRUN	= {8} ; (*	 "     status word RBF overrun mask   *)


  SEXTB_MSPON		= 1  ;	(* io_ExtFlags. Use mark-space parity,   *)
				(*	    instead of odd-even.	 *)
  SEXTF_MSPON		= 2  ;	(*    "	    mark-space parity mask	 *)
  SEXTB_MARK		= 0  ;	(*    "	    if mark-space, use mark	 *)
  SEXTF_MARK		= 1  ;	(*    "	    if mark-space, use mark mask *)

  SerErr_DevBusy	= 1  ;
  SerErr_BufErr		= 4  ;	(* Failed to allocate new read buffer *)
  SerErr_InvParam 	= 5  ;
  SerErr_LineErr	= 6  ;
  SerErr_ParityErr      = 9  ;
  SerErr_TimerErr	= 11 ;	(* (See the serial/OpenDevice autodoc)*)
  SerErr_BufOverflow    = 12 ;
  SerErr_NoDSR		= 13 ;
  SerErr_DetectedBreak  = 15 ;

  SERIALNAME		= "serial.device" ;

END Serial.
